package com.cloudptt.wp.ui.more;

import com.cloudptt.api.models.lbs.ReportData;
import com.cloudptt.api.product.INewReport;
import com.cloudptt.api.product.Product;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.cloudptt.wp.SysApplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

public class UserInfoActivity extends Activity implements OnClickListener,INewReport{

	private static final String TAG = "UserInfoActivity";

	private TextView latTV;
	private TextView lngTV;

	private TextView workHoursTV;
	private TextView heartRateTV;
	private TextView oxygenVolumeTV;
	private TextView batteryTV;
	private TextView callDescTV;


	private Product product;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		Window window = getWindow();
		window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
		window.setStatusBarColor(getResources().getColor(R.color.app_theme_color_primary));
		super.onCreate(savedInstanceState);
		getActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.app_theme_color_primary));
		getActionBar().hide();

		if(product == null){
			SysApplication app = ((SysApplication) getApplicationContext());
			product = app.getProduct();
		}

		setContentView(R.layout.user_info_layout);

		ImageView iv = (ImageView) findViewById(R.id.back_up_icon);
		iv.setOnClickListener(this);
		TextView tv = (TextView) findViewById(R.id.titleTv);
		tv.setText(getResources().getString(R.string.user_report_info));

		latTV = (TextView)findViewById(R.id.lat_info);
		lngTV = (TextView)findViewById(R.id.lng_info);

		workHoursTV = (TextView)findViewById(R.id.work_hours);
		heartRateTV = (TextView)findViewById(R.id.heart_rate);
		oxygenVolumeTV = (TextView)findViewById(R.id.oxygen_volume);
		batteryTV = (TextView)findViewById(R.id.battery_volume);
		callDescTV = (TextView)findViewById(R.id.call_desc_volume);

		if(product != null){
			ReportData data = product.getReportData();
			initData(data);
		}
		
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		
		SysApplication app = ((SysApplication) getApplicationContext());
		this.product = app.getProduct();
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Log.d(TAG, "onPause");
	}

	private void initData(ReportData data){
		Log.d(TAG, "initData data = "+data);
		if(data != null)
		{
			if(data.getLocData() != null)
			{
				//latTV.setText("Lat : " + data.getLocData().getLattitude());
				String latStr = getResources().getString(R.string.lat_text).format(getResources().getString(R.string.lat_text), data.getLocData().getLattitude());
				latTV.setText(latStr);
				String lngStr = getResources().getString(R.string.lng_text).format(getResources().getString(R.string.lng_text), data.getLocData().getLattitude());
				lngTV.setText(lngStr);
			}
//			if(data.getVitalData() != null)
//			{
//				String workHourStr = getResources().getString(R.string.workhour_text).format(getResources().getString(R.string.workhour_text), data.getVitalData().getWorkHours());
//				workHoursTV.setText(workHourStr);
//				String heartRateStr = getResources().getString(R.string.heartrate_text).format(getResources().getString(R.string.heartrate_text), data.getVitalData().getHeartRate());
//				heartRateTV.setText(heartRateStr);
//				String oxygenStr = getResources().getString(R.string.oxygen_text).format(getResources().getString(R.string.oxygen_text), data.getVitalData().getOxygenVolume());
//				oxygenVolumeTV.setText(oxygenStr);
//				String batteryStr = getResources().getString(R.string.battery_text).format(getResources().getString(R.string.battery_text), data.getVitalData().getBattery());
//				batteryTV.setText(batteryStr);
//				String callStr = getResources().getString(R.string.callstate_text).format(getResources().getString(R.string.callstate_text), data.getVitalData().getCallDesp());
//				callDescTV.setText(callStr);
//			}
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int id = v.getId();
		if(id == R.id.back_up_icon){
			this.finish();
		}
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	public void newReport(ReportData data) {
		// TODO Auto-generated method stub
		initData(data);
	}

}
